// pages/staff/orderDetail/orderDetail.ts

import {
  sonOrderDetail
} from "../../../http/api"
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: "",
    goodName: "",
    orderStatusArr: [],
    orderStatus:"",
    sonOrderStatus:[],
    orderObj:{},
  
    imgArr:[],
    orderStatusStr: "",
    orderStatusValue:"",

    isShow:false,
    imgIndex:0
  },

  handleShow(e){
    const {index} = e.currentTarget.dataset
    this.setData({
      isShow:true,
      imgIndex:index
    })
  },

  handleClose(){
   
    this.setData({
      isShow:false
    })
  },
  getData() {

    const {
      id,
      orderType,
      orderId
    } = this.data
    const params = {
      id,
      orderType,
      orderId
    }
    sonOrderDetail(params).then(res => {
      if (res.data.code === 200) {
        this.setData({
          orderObj: {
            ...res.data.data
          },
        })


        const orderStatusArr = app.getSonOrderStatusArr()
        let orderStatusStr = ""
        let orderStatusValue = ""
         //外卖单
         if(orderType==0){
          orderStatusStr = orderStatusArr[this.data.orderObj.status]
          orderStatusValue = this.data.orderObj.status
        }
        //包月单
        if(orderType==1){
          orderStatusStr = orderStatusArr[this.data.orderObj.orderChildList[0].status]
          orderStatusValue = this.data.orderObj.orderChildList[0].status

          if(res.data.data.orderChildList[0].sendPicList){
            this.setData({
              imgArr:[...res.data.data.orderChildList[0].sendPicList]
            })
          }
        }

        this.setData({
          orderStatusStr,
          orderStatusValue
        })
        
        
      }
    }).finally(() => {
      wx.hideLoading()
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const {
      id,
      orderType,
      orderId
    } = options
    console.log(options)
    if (id && orderType && orderId) {
      this.setData({
        id,
        orderType,
        orderId
      })
      this.getData()
    }

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    // this.setData({
    //   sonOrderStatus:app.getSonOrderStatusArr()
    // })

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})